﻿using System.Data.Common;
using System.Data.Entity.Infrastructure.Interception;
using System.Diagnostics;

namespace MesBSW.DAL
{
    public class MyCommandInterceptor : DbCommandInterceptor
    {
        public override void ReaderExecuting(DbCommand command, DbCommandInterceptionContext<DbDataReader> interceptionContext)
        {
            LogSql(command);
            base.ReaderExecuting(command, interceptionContext);
        }

        public override void ScalarExecuting(DbCommand command, DbCommandInterceptionContext<object> interceptionContext)
        {
            LogSql(command);
            base.ScalarExecuting(command, interceptionContext);
        }

        private void LogSql(DbCommand command)
        {
            Debug.WriteLine("----------SQL----Begin------");
            Debug.WriteLine($"{command.CommandText}");
            Debug.WriteLine("----------SQL----End--------");
        }
    }
}
